import { API_LIST } from '../../../Api/Api'
import { BuiltInData } from '../Common/common'
import { AddDataButton, DelDataButton, AnnexButton } from '../Common/options'

export const InspectionProblem = async ({ OptionsEvent, oneData, Permission, type }) => {
    const mapping = {
        quality: {
            get: API_LIST()['getQualityAttachment'],
            added: 'posQualityAttachment',
            del: 'QualityAttachment',
            initUuid: 'qualityUuid',
        },
        security: {
            get: API_LIST()['getSecurityAttachment'],
            added: 'posSecurityAttachment',
            del: 'SecurityAttachment',
            initUuid: 'securityUuid',
        },
    }
    const { get, added, del, initUuid } = mapping[type]
    const data = {
        hideInSearch: true,
        pageSize: 10,
        initialValues: { [initUuid]: oneData.uuid },
        params: { pageIndex: 1, [initUuid]: oneData.uuid },
        get,
        added,
        options: [
            oneData.auditStatus === -1 && (
                <AddDataButton OptionsEvent={OptionsEvent} type="primary" icon="add" title="新增问题信息" />
            ),
        ],
        columns: [
            // 名称 描述 日期
            {
                dataIndex: initUuid,
                title: initUuid,
                valueType: 'hidden',
                hideInTable: true,
            },
            {
                dataIndex: 'originalName',
                title: '文件标题',
                valueType: 'input',
                hideInAdded: true,
                hideInModify: true,
            },
            {
                dataIndex: 'fileType',
                title: '文件类型',
                valueType: 'select',
                valueEnum: BuiltInData.FileType,
                hideInAdded: true,
                hideInModify: true,
                rules: true,
                width: 350,
            },
            {
                dataIndex: 'attachmentUuid',
                title: '问题附件',
                valueType: 'upload',
                valueFile: [1],
                fileUrl: 'fileUrl',
                rules: true,
                hideInTable: true,
            },
            {
                dataIndex: 'fileUrl',
                title: '文件附件',
                valueType: 'hidden',
                hideInSearch: true,
                hideInTable: true,
                hideInAdded: true,
                hideInModify: true,
                width: 400,
            },
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 300,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { uuid, fileUrl } = record
                    return [
                        fileUrl && <AnnexButton OptionsEvent={OptionsEvent} key="see" url={fileUrl} title="查看附件" />,
                        oneData.auditStatus === -1 && (
                            <DelDataButton
                                OptionsEvent={OptionsEvent}
                                key="del"
                                title="删除"
                                url={del}
                                uuid={[oneData.uuid, uuid]}
                            />
                        ),
                    ]
                },
            },
        ],
    }

    return data
}
